package com.briup.jz.web.controller;

import com.briup.jz.bean.Comment;
import com.briup.jz.bean.User;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author
 * @project: jz
 * @description:
 * @create: 2020/6/13 23:19
 */
@RestController
@RequestMapping("/comment")
@Api(description = "评论管理接口，score=-1为投诉")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    /**
     * 1. 发表/修改评论
     */
    @ApiOperation(value = "发表或修改评论，不传入id则为发表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论的唯一编号，不传入则为发表评论", paramType = "query"),
            @ApiImplicitParam(name = "commentTime", value = "不填，发表/修改评论的时间", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "顾客id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "非空则为追评", paramType = "query"),
            @ApiImplicitParam(name = "score", value = "请给此次服务评分（1~5分）", required = true, paramType = "query"),
            @ApiImplicitParam(name = "content", value = "请评论", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "发表评论时应不填，默认为“待审核”", paramType = "query")
    })
    @PostMapping("commentOrUpdate")
    public Message comment(Comment comment){
        commentService.checkOrderStatus(comment.getOrderId());
        commentService.commentOrUpdate(comment);
        return MessageUtil.success("操作成功");
    }


    /**
     *  2.查看评论
     */
    @ApiOperation(value = "通过id查看评论及其子评论（可作为查看详情）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论的id，唯一标识", required = true, paramType = "query")
    })
    @GetMapping("findByIdWithFollow")
    public Message findByIdWithFollow(long id){
        return MessageUtil.success("查看成功", commentService.findByIdWithFollow(id));
    }

    @ApiOperation(value = "查看全部评论及其子评论")
    @GetMapping("findAllWithFollow")
    public Message findAllWithFollow(){
        return MessageUtil.success("查看成功", commentService.findAllWithFollow());
    }

    @ApiOperation(value = "查看全部评论(非投诉)")
    @GetMapping("findAllComments")
    public Message findAllComments(){
        return MessageUtil.success("查看成功", commentService.findAllComments());
    }


    /**
     *  3.删除评论
     */
    @ApiOperation(value = "通过id删除评论（级联删除）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论的id，唯一标识", required = true, paramType = "query")
    })
    @GetMapping("deleteById")
    public Message deleteById(long id){
        commentService.deleteById(id);
        return MessageUtil.success("删除成功");
    }


    /**
     * 4. 审核评论
     */
    @ApiOperation(value = "审核评论，修改评论的状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论的id，唯一标识", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "评论的状态，要求为“1”或“-1”，1代表审核通过，-1代表审核不通过", required = true, paramType = "query")
    })
    @PostMapping("updateStatus")
    public Message updateStatus(long id, String status){
        commentService.updateStatus(id, status);
        return MessageUtil.success("审核成功");
    }


    /**
     * 5. 顾客投诉
     */
    @ApiOperation(value = "顾客发起投诉")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "顾客id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "content", value = "请说明投诉理由", required = true, paramType = "query"),
    })
    @PostMapping("initiateComplaint")
    public Message initiateComplaint(long orderId, long userId, String content){
        commentService.initiateComplaint(orderId, userId, content);
        return MessageUtil.success("成功发起投诉");
    }


    @ApiOperation(value = "通过ID进行审核通过")
    @ApiImplicitParam(name = "id", value = "审核唯一编号", required = true, paramType = "query",dataType = "long")
    @GetMapping("auditing")
    public Message auditing(long id){
        commentService.updateStatus(id,"启用");
        return MessageUtil.success("审核成功");
    }

    @ApiOperation(value = "通过ID进行审核拒绝")
    @ApiImplicitParam(name = "id", value = "审核唯一编号", required = true, paramType = "query",dataType = "long")
    @GetMapping("refuseauditing")
    public Message refuseauditing(long id){
        commentService.updateStatus(id,"禁用");
        return MessageUtil.success("审核成功");
    }




//    @ApiOperation(value = "顾客发起投诉")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "不填，评论的唯一编号", paramType = "query"),
//            @ApiImplicitParam(name = "commentTime", value = "不填，发起投诉的时间", paramType = "query"),
//            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, paramType = "query"),
//            @ApiImplicitParam(name = "userId", value = "顾客id", required = true, paramType = "query"),
//            @ApiImplicitParam(name = "parentId", value = "不填）", paramType = "query"),
//            @ApiImplicitParam(name = "score", value = "不填，投诉默认为“-1”", paramType = "query"),
//            @ApiImplicitParam(name = "content", value = "请说明投诉理由", required = true, paramType = "query"),
//            @ApiImplicitParam(name = "status", value = "不填，默认为“待仲裁”", paramType = "query")
//    })
//    @PostMapping("initiateComplaint")
//    public Message initiateComplaint(Comment comment){
//        commentService.initiateComplaint(comment);
//        return MessageUtil.success("成功发起投诉");
//    }

}
